package com.xuyuan.concurrent.test;

public class Count {
    public int num = 0;
    private byte[] lock = new byte[0];

    public synchronized void methodA() {
        try {
            Thread.sleep(51);// 模仿用户干活
        } catch (InterruptedException e) {
        }
        num += 1;
        System.out.println(Thread.currentThread().getName() + "-" + num);
    }

    public void methodB() {
        synchronized (lock) {
            try {
                Thread.sleep(51);// 模仿用户干活
            } catch (InterruptedException e) {
            }
            num += 1;
            System.out.println(Thread.currentThread().getName() + "-" + num);
        }
    }
}
